package com.park.service.impl;

import com.park.bean.Tickets;
import com.park.bean.TicketsRec;
import com.park.bean.TicketsType;
import com.park.dao.ITicketsRecDao;
import com.park.service.ITicketsRecService;
import com.park.util.Page;
import org.apache.poi.hpsf.Decimal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Service
public class TicketsRecServiceImpl implements ITicketsRecService {
    @Autowired
    ITicketsRecDao dao;
    @Override
    public List<TicketsRec> getTicketsRec(TicketsRec ticketsRec, Page page) {
        return dao.getTicketsRec(ticketsRec, page);
    }

    @Override
    public int getCount(TicketsRec ticketsRec) {
        return dao.getCount(ticketsRec);
    }

    @Override
    public int checkExist(TicketsRec ticketsRec) {
        return dao.checkExist(ticketsRec);
    }

    @Override
    public List<Tickets> getTicketsFromRec() {
        return dao.getTicketsFromRec();
    }

    @Override
    public List<TicketsType> getTicketsTypeFromRec() {
        return dao.getTicketsTypeFromRec();
    }


    @Override
    @Transactional
    public int postTicketsRec(TicketsRec ticketsRec) {
        BigDecimal price=dao.getPrice(ticketsRec.getTicketsId());
        BigDecimal ratio=dao.getRatio(ticketsRec.getTypeId());
        BigDecimal result=price.multiply(ratio);
        ticketsRec.setPrice(result);
        return dao.postTicketsRec(ticketsRec);
    }

    @Override
    public int delTicketsRec(int id) {
        return dao.delTicketsRec(id);
    }

    @Override
    public int editTicketsRec(TicketsRec ticketsRec) {
        System.out.println(ticketsRec.getNum()+"editTicketsRec");
        return dao.editTicketsRec(ticketsRec);
    }
}
